package cn.wolfcode.web.interceptor;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //获取登录用户
        //HttpSession session = request.getSession();
        //Object employee = session.getAttribute("USER_IN_SESSION");
        Employee employee = UserContext.getCurrentUser();
        //判断是否有登录用户,若有则放行
        if (employee != null){
            return true;
        }
        //若没有则跳转到登录页面,并不放行
        response.sendRedirect("/login.html");
        return false;
    }
}
